<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>路由</title>
</head>

<body>
    <div id="btn">跳转</div>
    <script>
        // BrowerRouter  HashRouter 错误 这只是react DOM 的组件而已
        // 前端路由：hash路由 和 history 
        // hash 以#开始  兼容性 好, 缺点不如history 和后端路由一样
        // hashChange pushState（html5 history对象上） 当前页面不会跳转，依赖的规则不一样
        const btn = document.querySelector('#btn')
        btn.addEventListener('click', (event) => {
            window.location.href = '#/user' //BOM  url 发送改变但不跳转
        })
        window.onhashchange = (event) => {
            const newURL = event.newURL;
            const oldURL = event.oldURL;
            console.log(newURL, oldURL, location.hash);
        }
    </script>
</body>

</html>